package com.aishua.fire.controller;

import java.util.List;

import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aishua.fire.common.JsonArrayResult;
import com.aishua.fire.common.JsonObjectResult;
import com.aishua.fire.common.ValidateUtil;
import com.aishua.fire.common.anno.ModuleService;
import com.aishua.fire.common.constant.BigMenuConstants;
import com.aishua.fire.common.constant.ModuleConstants;
import com.aishua.fire.common.exp.ValidateException;
import com.aishua.fire.entity.checkcatalog.AddCheckCatalogInfo;
import com.aishua.fire.entity.checkcatalog.CheckCatalogInfo;
import com.aishua.fire.service.CheckCatalogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api(value = "检查项目分类目录管理",tags = {"检查项目分类目录管理模块接口"})
@RestController
@Slf4j
public class CheckCatalogManagerController
{

	@Autowired
	private CheckCatalogService catalogService;
	
	@Autowired
	private ValidateUtil validateUtil;
	
	@SuppressWarnings("rawtypes")
	@ModuleService(totalModule=BigMenuConstants.checkManager,moduleName=ModuleConstants.checkManager)
	@ApiOperation(value="检查项目分类目录_新增分类目录信息")
	@PostMapping(value = {"/checkcatalog"} )
	public ResponseEntity<JsonObjectResult> add(@RequestBody @Valid AddCheckCatalogInfo info, BindingResult result) throws ValidateException
	{
		log.info("检查项目分类目录_新增分类目录信息:{}",info);
		validateUtil.respErrorMsg(result);//非空验证
		catalogService.save(info);
		JsonObjectResult r = JsonObjectResult.makeSuccessResult(null);

		return ResponseEntity.ok(r);
    }
	
	
	/**
	 * 检查项目分类目录_查询分类目录信息
	 */
	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "检查项目分类目录_查询分类目录信息")
	@GetMapping(value = { "/checkcatalog" })
	public ResponseEntity<JsonArrayResult> list(
			@RequestParam(name = "name") String name,
			@RequestParam(name = "pageNumber") int pageNumber, @RequestParam(name = "pageSize") int pageSize) 
	{
		log.info("检查项目分类目录_查询分类目录信息  查询列表请求参数:{}");
		
		List<CheckCatalogInfo> catalogs = catalogService.list(name, pageNumber, pageSize);
		int total = catalogService.listTotal(name);
		log.info("查询总条数：{}", total);
		JsonArrayResult r = JsonArrayResult.makeSuccessResult(catalogs, total);

		return ResponseEntity.ok(r);
	}
	
	/**
	 * 检查项目分类目录_查询分类目录所有列表信息下拉框
	 */
	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "检查项目分类目录_查询分类目录所有列表信息下拉框")
	@GetMapping(value = { "/getCheckcatalogSelectList" })
	public ResponseEntity<JsonArrayResult> getSelectList() 
	{
		log.info("检查项目分类目录_查询分类目录所有列表信息下拉框 请求参数:{}");
		List<CheckCatalogInfo> list = catalogService.getCheckcatalogSelectList();
		JsonArrayResult r = JsonArrayResult.makeSuccessResult(list, 0);

		return ResponseEntity.ok(r);
	}
	
	/**
	 * 检查项目分类目录_修改分类目录信息
	 */
	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "检查项目分类目录_修改分类目录信息")
	@PutMapping(value = { "/checkcatalog" })
	public ResponseEntity<JsonObjectResult> updateCatalogInfo(@RequestBody CheckCatalogInfo info) 
	{
		log.info("检查项目分类目录_修改分类目录信息  修改列表请求参数:{}", info);
		
		catalogService.updateCatalogInfo(info);
		JsonObjectResult r = JsonObjectResult.makeSuccessResult(null);

		return ResponseEntity.ok(r);
	}
	
}